<template>
	<view class="exchange_record">
		<mescroll-body @init="mescrollInit" @down="downCallback" @up="upCallback">
			<!-- 数据列表 -->
			<view class="list-box" v-if="list.length > 0">
				<view class="list-item" v-for="data in list">
					<view class="up-box">
						<view class="order-view">订单号: {{data.order_no}}</view>
						<block v-if="data.type == 1">
							<view class="order-state" :class="data.status_take == 3 ? 'gray' : ''">
								{{data.status_take_name}}
							</view>
						</block>
						<block v-else>
							<view class="order-state" :class="data.status_sale == 3 ? 'gray' : ''">
								{{data.status_sale_name}}
							</view>
						</block>
					</view>
					<view class="order-content">
						<image class="img" :src="$util.img(data.sku_img)"></image>
						<view class="content-sp">
							<view class="goods-name">{{data.sku_name}}</view>
							<view class="goods-num">x{{data.num}}</view>
						</view>
					</view>
					<view class="line"></view>
					<view class="down-box">
						<view class="left-b">
							<text class="text">兑换券</text>
							<text class="text red">{{data.price}}</text>
						</view>
						<view class="but" @click="viewDetail(data.id)">查看详情</view>
					</view>
				</view>
			</view>
			<view v-else><ns-empty :isIndex="!1" :fixed="true" text="暂无数据"></ns-empty></view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				list: [],
			};
		},
		methods: {
			upCallback(page) {
				this.$api.sendRequest({
					url: '/exchange/api/order/orderList',
					data: {
						page: page.num,
						page_size: page.size,
					},
					success: res => {
						if (res.code == 0) {
							let newArr = [];
							if (page.num == 1) this.list = [];
							newArr = res.data.list;
							this.list = this.list.concat(newArr);
							this.mescroll.endSuccess(res.data.list.length);
							if (this.list.length == 0) {
								this.mescroll.showEmpty();
							}
						} else {
							this.mescroll.endErr();
						}
					}
				})
			},
			/* 查看详情 */
			viewDetail(id) {
				this.$util.redirectTo('/xxjk/exchange/exchange_particulars/exchange_particulars', {
					id: id,
				});
			}
		}
	}
</script>

<style lang="scss">
	.exchange_record {
		.list-box {
			padding: 0 24rpx;

			.list-item {
				padding: 24rpx;
				background-color: #fff;
				border-radius: 16rpx;
				margin-top: 20rpx;

				.up-box {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.order-view {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 26rpx;
						color: #777777;
						line-height: 50rpx;
					}

					.order-state {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 26rpx;
						color: #FC311A;
						line-height: 50rpx;

						&.gray {
							color: #777777;
						}
					}
				}

				.order-content {
					margin-top: 20rpx;
					display: flex;

					.img {
						min-width: 128rpx;
						max-width: 128rpx;
						height: 128rpx;
					}

					.content-sp {
						display: flex;
						justify-content: space-between;
						margin-left: 24rpx;
						width: 100%;

						.goods-name {
							font-family: PingFang SC, PingFang SC;
							font-weight: 500;
							font-size: 28rpx;
							color: #222222;
							line-height: 33rpx;
						}

						.goods-num {
							margin-left: 58rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 28rpx;
							color: #999999;
							line-height: 33rpx;
						}
					}
				}

				.line {
					margin-top: 24rpx;
					background-color: #EBEBEB;
					width: 100%;
					height: 2rpx;
				}

				.down-box {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding-top: 26rpx;

					.left-b {
						.text {
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 28rpx;
							color: #000000;
							line-height: 50rpx;
						}

						.red {
							margin-left: 10rpx;
							color: #FC311A;
						}
					}

					.but {
						width: 144rpx;
						height: 56rpx;
						border-radius: 200rpx 200rpx 200rpx 200rpx;
						border: 2rpx solid #EBEBEB;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 26rpx;
						color: #222222;
						line-height: 50rpx;
						display: flex;
						align-items: center;
						justify-content: center;
					}
				}
			}
		}
	}
</style>